Skip to content

perf(queue): share SABnzbd's history read while it shows post-processing, and smaller follow-ups - #700

Merged
bardesss merged 1 commit into
bardesss:mainfrom
ghostintherack:fix/689-followups
Nov 17, 2026
Merged

bardesss merged 1 commit into
bardesss:mainfrom
ghostintherack:fix/689-followups

Conversation

@ghostintherack

Copy link
Copy Markdown
Contributor

Your three optional follow-ups on #689.

  • The history read is shared while it shows post-processing. Where SABnzbd's queue reads paused and its slots cannot tell the wait from a pause by hand, #waitOn reads the switch, shared for ten seconds, and, when it is on, the history's first ten rows, which it read again on every call. A history read that shows a download in post-processing is now shared the same way. cached() takes an optional keep check for that, applied under the identity check that already guards a failed read (the reason TtlCache.get gives for ttlFor), so a later read in its place is never dropped. While the wait lasts, the calls that reach the read (get_queue, diagnose_media, pause_downloads and retry_download among them) share one request every ten seconds. A read that shows none is not kept, so a queue paused by hand still costs one history read per call, as on main. Keeping it would let a stale "nothing in post-processing" stand for up to ten seconds after post-processing starts: pause_downloads would answer "already paused" for a queue the wait has just started holding, and send nothing, and get_queue, diagnose_media and retry_download would name a pause by hand, or no hold for a Force job. For up to ten seconds after the wait ends, a queue still paused by hand can read as the wait, as it already does during the wait; the pause_downloads section of docs/tools.md now says so. A failed read still answers no, and the next call reads again. get_stack_health never reaches this read: the only queues it reads are those of the torrent clients a Cleanuparr rule set maps.
  • The hold read-back no longer depends on order. retry_download's applied took the hold whose HOLD_FIELDS entry, joined, equalled the flags set, joined in HOLD_FLAGS order. It now takes the hold whose fields are exactly the ones set, whatever their order.
  • The long line. The rest of that pause_downloads paragraph is re-wrapped from the changed sentence on, so no line in it runs past 80 columns.

No tool description, preview or other client text changes.

Verified

The changed test, which expects one history read across two getQueue calls and a pause state read while the history shows the wait, fails on main, which makes three. A new test has the history show nothing and then a download in post-processing, and checks that getQueue and the pause state read find the wait on the next call; it fails with a cache that also keeps a history showing nothing, and on main, which reads four times. A tool-level test checks that a pause_downloads preview stops being a no-op once the wait starts; it fails with a cache that keeps a history showing nothing. Another refuses the first history read and checks that the next call reads again and finds the wait; it fails with a cache that keeps the failed read. Three new cached() tests check that a read keep refuses is read again, that a refused read resolving late leaves a newer one in place, and that a keep that throws drops its read; each fails with its guard removed. With queueAndPostPaused's two flags swapped in HOLD_FIELDS, the retry_download test for that hold fails on main and passes here, and a read-back that takes a hold whose fields are only some of those set is caught too.

There is no SABnzbd test instance, so this rests on the tests, as #689 did.

Gates on Node 24.22.2: lint, typecheck, build and codegen exit 0 with no generated diff, and 207 test files / 7,182 tests pass (main: 7,176).

…ing, and smaller follow-ups

Where SABnzbd's queue reads paused and its slots cannot tell the wait
for post-processing from a pause by hand, `#waitOn` reads the "Pause
Downloading During Post-Processing" switch, shared for ten seconds,
and, when it is on, the history's first ten rows, which it read again
on every call. A history read that shows a download in post-processing
is now shared the same way: `cached()` takes a `keep` check, applied
under the identity check that already guards a failed read, so a later
read in its place is never dropped. While the wait lasts, the calls
that reach the read (get_queue, diagnose_media, pause_downloads and
retry_download among them) share one request every ten seconds, and
for up to ten seconds after it ends the queue can still read as held
by it. A read that shows none is not kept, since post-processing can
start at any moment: a stale "nothing in post-processing" would have
pause_downloads answer "already paused" for a queue the wait has just
started holding, and send nothing, and would have get_queue,
diagnose_media and retry_download name a pause by hand, or no hold for
a Force job, where the wait holds the download. A failed read still
answers no, and the next call reads again. get_stack_health never
reaches this read.

retry_download read its hold back by joining the flags set in
`HOLD_FLAGS` order and comparing that with each `HOLD_FIELDS` entry
joined, which held only while every entry listed its flags in that
order. It now takes the hold whose fields are exactly the ones set,
whatever their order.

docs/tools.md says which history reads are shared, and the rest of
that pause_downloads paragraph is re-wrapped, so no line in it runs
past 80 columns.
@bardesss

Copy link
Copy Markdown
Owner

Thanks, this looks good. The keep handling in cached() is sound (the identity check covers a late refused read, and a throwing keep drops without leaking), and the exact-fields match in retry_download fixes the order dependency. A few optional notes, none blocking:

  1. The ten-second window reaches more than pause_downloads. A kept history that shows a download in post-processing also feeds get_queue, diagnose_media and retry_download. If the wait ends and the queue is paused by hand within those ten seconds, they still name the post-processing wait, and diagnose_media / retry_download say SABnzbd resumes by itself, which it won't. The trade-off is fine, but it might be worth a line in those tools' docs too, not only the pause_downloads section.
  2. Resume preview in that window. A resume previewed then says downloading starts once the wait ends, though the wait is already over. The resume is still sent, so the queue starts right away; only the preview wording is off.
  3. Readability of the read-back. The find(hold => HOLD_FLAGS.every(...)) expression in src/tools/retryDownload.ts sits inside the object spread at around 200 columns. A small named helper next to HOLD_FIELDS (say holdOf(r)) would read more easily and could be tested on its own.

@bardesss
bardesss merged commit b7eabb3 into bardesss:main Nov 17, 2026
2 checks passed
@ghostintherack
ghostintherack deleted the fix/689-followups branch November 17, 2026 14:49
bardesss pushed a commit that referenced this pull request Nov 17, 2026
…he shared history read for two more tools (#702)

retry_download's `applied` read its hold back with a `find()` inside
the object spread of its outcome. That expression is now `holdOf`,
next to `HOLD_FIELDS`, exported and tested on its own: the hold whose
fields are exactly the flags set, whatever their order.

SABnzbd's history read is shared for ten seconds while it shows a
download in post-processing (#700), so for up to ten seconds after the
wait ends a queue paused by hand can still read as the wait. The
pause_downloads section of docs/tools.md said so; the diagnose_media
and retry_download sections now say it too, and the pause_downloads
section words the resume preview's wait sentence as the condition it
is. Each paragraph is re-wrapped from the changed line on. get_queue
makes the same read but reports no hold (its rows leave `heldBy` out),
so its section needs nothing.

Co-authored-by: arr-mcp-contributor <contributor@example.invalid>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants